package com.shg.web.action;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.shg.bean.Channel;
import com.shg.bean.PageView;
import com.shg.service.ChannelService;

@Controller
public class ChannelAction {

	//频道
	private Channel channel;
	//分页
	private PageView<Channel> pageView;
	//每页显示的最大记录
	private int maxrecord=15;
	//当前页
	private int currentpage=1;
	private String message;
	
	
	
	@Resource private ChannelService channelService;
	/**
	 * 模板查询
	 * @return
	 */
	public String list(){
		pageView=new PageView<Channel>(maxrecord, currentpage);
		try {
			pageView.setQueryResult(channelService.getView(pageView));
		} catch (Exception e) {
			e.printStackTrace();
			this.message="操作发生异常";
			return "error";
		}
		return "list";
	}
	/**
	 * 添加频道
	 * @return
	 */
	public String add(){
		try {
			channel.setName(URLDecoder.decode(channel.getName(), "UTF-8"));
			channel.setPosition(URLDecoder.decode(channel.getPosition(), "UTF-8"));
			channel.setMould(URLDecoder.decode(channel.getMould(), "UTF-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		channelService.insert(channel);
		return "add";
	}

	public Channel getChannel() {
		return channel;
	}

	public void setChannel(Channel channel) {
		this.channel = channel;
	}
	public PageView<Channel> getPageView() {
		return pageView;
	}
	public void setPageView(PageView<Channel> pageView) {
		this.pageView = pageView;
	}
	public int getMaxrecord() {
		return maxrecord;
	}
	public void setMaxrecord(int maxrecord) {
		this.maxrecord = maxrecord;
	}
	public int getCurrentpage() {
		return currentpage;
	}
	public void setCurrentpage(int currentpage) {
		this.currentpage = currentpage;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
}
